home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / MPW Related / Animated Cursors / WindowTkl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-14  |  6.9 KB  |  226 lines  |  [TEXT/MPS ]

  1. /******************************************************************************\
  2. * Header Files
  3. \******************************************************************************/
  4.  
  5. #include <Controls.h>
  6. #include <Desk.h>
  7. #include <Events.h>
  8. #include <Memory.h>
  9. #include <Script.h>
  10. #include <Windows.h>
  11. #include "CursWindTkl.h"
  12. #include "ShowCursor.h"
  13. #include "WindowTkl.h"
  14.  
  15.  
  16. /******************************************************************************\
  17. * Constants & Macros
  18. \******************************************************************************/
  19.  
  20. #define titleBarHeight 18 //Height of docWindProc title bar in pixels
  21. #define userWindMarg   50 //User window margin
  22. #define stdWindMarg    3  //Zoom window margin
  23.  
  24.  
  25. #pragma segment Main
  26. /******************************************************************************\
  27. * DoUpdateEvent - Handles a window update event
  28. *
  29. * DoUpdateEvent handles a window update event by drawing the window grow icon.
  30. \******************************************************************************/
  31.  
  32. void
  33. DoUpdateEvent (TheEvent)
  34.     EventRecord *TheEvent; //-> Update event 
  35.     {
  36.     WindowPtr UpdtWind; //-> Window to update
  37.     GrafPtr   SavePort; //-> Saved port
  38.  
  39.     GetPort (&SavePort);
  40.     UpdtWind = (WindowPtr) TheEvent->message;
  41.     SetPort (UpdtWind);
  42.     BeginUpdate (UpdtWind);
  43.     EraseRect (&UpdtWind->portRect);
  44.     DrawCursWind (UpdtWind);
  45.     EndUpdate (UpdtWind);
  46.     SetPort (SavePort);
  47.     }
  48.  
  49.  
  50. #pragma segment Main
  51. /******************************************************************************\
  52. * DoActivateEvent - Handles a window activate event
  53. *
  54. * DoActivateEvent handles a window activate event.
  55. \******************************************************************************/
  56.  
  57. void
  58. DoActivateEvent (ActiveWind, Active)
  59.     WindowPeek ActiveWind; //-> Window requiring activation/deactivation >>
  60.     short      Active;     //True if activating, false if deactivating >>
  61.     {
  62.     }
  63.  
  64.  
  65. #pragma segment Main
  66. /******************************************************************************\
  67. * DoContentEvent - Handle click in the windows content region
  68. *
  69. * DoContentEvent handles a click in the content region of the window specified
  70. * by ClickWind.  TheEvent points to the event record that recorded this click.
  71. \******************************************************************************/
  72.  
  73. void
  74. DoContentEvent (TheEvent, ClickWind)
  75.     EventRecord *TheEvent; //-> Drag click event >>
  76.     WindowPtr   ClickWind; //-> Clicked window >>
  77.     {
  78.     if (ClickWind != FrontWindow ())
  79.         SelectWindow (ClickWind);
  80.     else if (windKindPtr (ClickWind) == cursWindKind)
  81.         ContentCursWind (TheEvent, ClickWind);
  82.     }
  83.  
  84.  
  85. #pragma segment Main
  86. /******************************************************************************\
  87. * DoDragEvent - Handle click in title bar
  88. *
  89. * DoDragEvent handles a click in the title bar to drag the window to a new
  90. * location.
  91. \******************************************************************************/
  92.  
  93. void
  94. DoDragEvent (TheEvent, ClickWind)
  95.     EventRecord *TheEvent; //-> Drag click event
  96.     WindowPtr   ClickWind; //-> Clicked window
  97.     {
  98.     Rect      LimitRect;  //Rect to limit dragging to
  99.     RgnHandle GrayRegion; //=> Desktop gray region
  100.  
  101.     GrayRegion = GetGrayRgn ();
  102.     LimitRect = (**GrayRegion).rgnBBox;
  103.     DragWindow (ClickWind, TheEvent->where, &LimitRect);
  104.     }
  105.  
  106.  
  107. #pragma segment Main
  108. /******************************************************************************\
  109. * DoGoAwayEvent - Handle click in close box
  110. *
  111. \******************************************************************************/
  112.  
  113. void
  114. DoGoAwayEvent (TheEvent, ClickWind)
  115.     EventRecord *TheEvent; //-> Drag click event >>
  116.     WindowPtr   ClickWind; //-> Clicked window <>
  117.     {
  118.     if (TrackGoAway (ClickWind, TheEvent->where))
  119.         {
  120.         if (windKindPtr (ClickWind) == cursWindKind)
  121.             CloseCursWind (ClickWind);
  122.         }
  123.     }
  124.  
  125.  
  126. #pragma segment Main
  127. /******************************************************************************\
  128. * DoZoomEvent - Handle click in zoom box
  129. *
  130. * DoZoomEvent handles a click in the zoom box of the window specified by
  131. * ClickWind.  
  132. \******************************************************************************/
  133.  
  134. void
  135. DoZoomEvent (TheEvent, ClickWind, PartCode)
  136.     EventRecord *TheEvent; //-> Drag click event >>
  137.     WindowPtr   ClickWind; //-> Clicked window <>
  138.     short       PartCode;  //inZoomIn or inZoomOut >>
  139.     {
  140.     GrafPtr CurrPort; //-> Current GrafPort
  141.  
  142.     if (TrackBox (ClickWind, TheEvent->where, PartCode))
  143.         {
  144.         GetPort (&CurrPort);
  145.         SetPort (ClickWind);
  146.         ZoomWindow (ClickWind, PartCode, true);
  147.         SetPort (CurrPort);
  148.         }
  149.     }
  150.  
  151.  
  152. #pragma segment Main
  153. /******************************************************************************\
  154. * CloseAllWindows - Close all open windows
  155. *
  156. * CloseAllWindows closes all the open windows.
  157. \******************************************************************************/
  158.  
  159. void
  160. CloseAllWindows ()
  161.     {
  162.     WindowPeek TheWindow; //-> window to close
  163.  
  164.     TheWindow = (WindowPeek) FrontWindow ();
  165.     while (TheWindow != (WindowPeek) null)
  166.         {
  167.         if (windKindPtr (TheWindow) < 0)
  168.             CloseDeskAcc (windKindPtr (TheWindow));
  169.         else if (windKindPtr (TheWindow) == cursWindKind);
  170.             CloseCursWind ((WindowPtr) TheWindow);
  171.         TheWindow = TheWindow->nextWindow;
  172.         }
  173.     }
  174.  
  175.  
  176. #pragma segment Main
  177. /******************************************************************************\
  178. * SetWindSize - Set user and standard sizes of window
  179. *
  180. * SetWindSize sets the user and standard sizes of the window specified by
  181. * TheWindow.  The userState and stdState rectangles in TheWindow’s WStateData
  182. * record are set to the main screen rectangle minus the menu bar and a certain
  183. * amount specified by the userWindMarg and stdWindMarg.
  184. \******************************************************************************/
  185.  
  186. void
  187. SetWindSize (TheWindow)
  188.     WindowPtr TheWindow; //-> Window to resize <>
  189.     {
  190.     Rect       WindRect;     //Rectangle of windows’s user and standard sizes
  191.     WStateData **WindStates; //=> Window zoom rectangles
  192.  
  193.     WindStates = (WStateData **) ((WindowPeek) TheWindow)->dataHandle;
  194.     WindRect = qd.screenBits.bounds;
  195.     WindRect.top += GetMBarHeight () + titleBarHeight;
  196.     InsetRect (&WindRect, userWindMarg, userWindMarg);
  197.     (**WindStates).userState = WindRect;
  198.     WindRect = qd.screenBits.bounds;
  199.     WindRect.top += GetMBarHeight () + titleBarHeight;
  200.     InsetRect (&WindRect, stdWindMarg, stdWindMarg);
  201.     (**WindStates).stdState = WindRect;
  202.     }
  203.  
  204.  
  205. #pragma segment Main
  206. /******************************************************************************\
  207. * FrontWindKind - Return pointer to frontmost window of a kind
  208. *
  209. * FrontWindKind returns a pointer to the frontmost window with a windowKind
  210. * field equal to WindKind.  If there aren't any windows with that windowKind,
  211. * null is returned.
  212. \******************************************************************************/
  213.  
  214. WindowPtr
  215. FrontWindKind (WindKind)
  216.     short WindKind; //Window kind to search for
  217.     {
  218.     WindowPeek CheckWind; //-> Window to check on
  219.  
  220.     CheckWind = (WindowPeek) FrontWindow ();
  221.     while (CheckWind != (WindowPeek) null && CheckWind->windowKind != WindKind)
  222.         CheckWind = CheckWind->nextWindow;
  223.     return (WindowPtr) CheckWind;
  224.     }
  225.